//index.js
//获取应用实例
const app = getApp()

Page({
	data: {
		num: 1,
		data: [],
		http: getApp().globalData.map,
		uid: '',
		index: 0,
	},
	index(e) {
		this.setData({
			index: e.currentTarget.dataset.id,
			data:[],
			pg:1
		})
	},
	list(e) {
		this.setData({
			data: [],
			index: e.detail.current
		})
		if (e.detail.current == 0) {
			this.push()
		} else {
			this.dp()
		}
	},
	onShow(){
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data,
					xin:1,
					data:[]
				})
				if (this.data.index == 0) {
					this.push()
				} else {
					this.dp()
				}
			}
		})
	},
	dp() {
		wx.request({
			url: getApp().globalData.http + 'action=shopGZ&uid=' + this.data.uid.uid + '&pg=' + this.data.num,
			success: (e) => {
				console.log(e)
				let a = this.data.data
				for (let i in e.data.data) {
					a.push(e.data.data[i])
				}
				let pd=1
				if (e.data.data.length < 15) {
					this.setData({
						pd: 0
					})
				}
				this.setData({
					data: a,
					pd:pd
				})
			}
		})
	},
	push() {
		console.log(this.data.uid.uid)
		wx.request({
			url: getApp().globalData.http+'action=mySclist&pg=' + this.data.num + '&uid=' + this.data.uid.uid,
			success: (e) => {
				console.log(e)
				let a = this.data.data
				if (this.data.xin == 1) {
					a = []
				}
				for (let i in e.data.data) {
					a.push(e.data.data[i])
				}
				if (e.data.data.length < 15) {
					this.setData({
						pd: 0
					})
				}
				this.setData({
					data: a,
					xin: 0
				})
			}
		})
	},
	ovo() {
		if (this.data.index == 0) {
			if (this.data.pd == 1) {
				this.setData({
					num: this.data.num + 1
				})
				this.push()
			}
		} else {
			if (this.data.pd == 1) {
				this.setData({
					num: this.data.num + 1
				})
				this.dp()
			}
		}
		
	}
})
